package api

import (
	"blizzard/app/model"
	"blizzard/app/service"
	"blizzard/app/utils/code"
	"blizzard/app/utils/response"
	"github.com/gogf/gf/net/ghttp"
)

var Card = new(apiCard)

type apiCard struct {}

func (a *apiCard) Add(r *ghttp.Request) {
	var (
		data *model.CardParam
		err error
	)
	if err = r.Parse(&data); err != nil {
		response.JsonExit(r, code.ParamError, err.Error())
	}
	add, err := service.Card.Add(data)
	if err != nil {
		response.JsonExit(r, code.ServerError, err.Error())
	}
	response.Json(r, code.Success, code.SuccessMsg, add)
}

func (a *apiCard) List(r *ghttp.Request) {
	var (
		err error
		list interface{}
	)
	list, err = service.Card.List()
	if err != nil {
		response.JsonExit(r, code.ServerError, err.Error())
	}
	response.Json(r, code.Success, code.SuccessMsg, list)
}